package eecs285.proj4.gui;

//Class: EECS 285
//Project: 
//Due Date: Monday December 6th, 2010

//NOTES: 
import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Point;
import java.util.ArrayList;
import static eecs.util.Utility.*;


/**
 * A derived class for actions performed on a Markerboard.
 * 
 * @author Easton Thomas
 * @author Stubbed by Hans Marquard
 */
@SuppressWarnings("serial")
public class FreeDraw extends MAction
{
  float alpha;
  
  // ---------------------------------------------------------------------------

  /**
   * Constructor.
   * 
   * @author Hans Marquard
   */
  public FreeDraw(Point new_point)
  {
    super(TYPE.FREEDRAW);
    points = new ArrayList<Point>();
    points.add(new_point);
  }

  // ---------------------------------------------------------------------------

  /**
   * Include an additional Point in the mouse movement.
   * 
   * @author Hans Marquard
   */
  public void add_point(Point new_point)
  {
    points.add(new_point);
  }

  // ---------------------------------------------------------------------------

  /**
   * Implementation of abstract draw method. Draws this type of object.
   * 
   * @param g2
   *          The Graphics object to draw on.
   * @author Easton Thomas
   * @author Stubbed by Hans Marquard
   */
  public void draw(Graphics2D g2)
  {

    g2.setStroke(new BasicStroke(stroke, BasicStroke.CAP_ROUND,
        BasicStroke.JOIN_ROUND)); // set line width of Marker
    g2.setColor(color);
    
    Point last = null;
    for(Point pt : points)
    {
    	if(last == null) last = pt;
    	else
    	{
    		g2.drawLine(last.x, last.y, pt.x, pt.y);
    		last = pt;
    	}
    }

    //old draw if you look at it will only draw the last two points
//    if( points.size() > 1 )
//    {
//      g2.drawLine(points.get(points.size() - 2).x, points
//          .get(points.size() - 2).y, points.get(points.size() - 1).x, points
//          .get(points.size() - 1).y);
//    }
    
  }// draw
  
}// FreeDraw
